package http

const (
	MethodGet     = "GET"
	MethodHead    = "HEAD"
	MethodPost    = "POST"
	MethodPut     = "PUT"
	MethodPatch   = "PATCH" // RFC 5789
	MethodDelete  = "DELETE"
	MethodConnect = "CONNECT"
	MethodOptions = "OPTIONS"
	MethodTrace   = "TRACE"

	HeaderSpend         = "Injoy-Spend"
	HeaderTry           = "Injoy-Try"
	HeaderContentType   = "Content-Type"
	HeaderAuthorization = "Authorization"
)

// NewClient
// 新建HTTP请求客户端
// 返回接口(做目录用,无其它作用)
func NewClient(fn ...func(c *Client)) *Client {
	data := &Client{Client: client(), init: fn}
	return data.reset()
}

func Get(url string, bind ...interface{}) *Response {
	client := DefaultClient.Url(url)
	if len(bind) > 0 {
		client.Bind(bind)
	}
	return client.Get()
}

func GetBytes(url string) ([]byte, error) {
	resp := DefaultClient.Url(url).Get()
	return resp.GetBody(), resp.Err()
}

func Post(url string, bind ...interface{}) *Response {
	client := DefaultClient.Url(url)
	if len(bind) > 0 {
		client.Bind(bind)
	}
	return client.Post()
}

func Put(url string, bind ...interface{}) *Response {
	client := DefaultClient.Url(url)
	if len(bind) > 0 {
		client.Bind(bind)
	}
	return client.Put()
}

func Delete(url string, bind ...interface{}) *Response {
	client := DefaultClient.Url(url)
	if len(bind) > 0 {
		client.Bind(bind)
	}
	return client.Delete()
}
func Url(url string) *Client {
	return DefaultClient.Url(url)
}
